

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketAddress;
import java.net.SocketException;

public class UDPClient {
    public static void main(String[] args) {
        try {
            DatagramSocket datagramSocket = new DatagramSocket(8888);
            byte[] bytes = new byte[1024];
            int length = 0;
            DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length);

            datagramSocket.receive(datagramPacket);
            String line = new String(datagramPacket.getData(), 0, datagramPacket.getLength());
            SocketAddress socketAddress = datagramPacket.getSocketAddress();
            System.out.println(socketAddress);
            System.out.println(line);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
